package com.service.impl;

import com.entity.Branch;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.BranchMapper;
import com.service.BranchService;
import com.vo.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ fileName:BranchServiceImpl
 * @ description:
 * @ author:dzh
 * @ createTime:2022/5/4 23:14
 * @ version:1.0.0
 */
@Service
public class BranchServiceImpl implements BranchService {
    @Resource
    private BranchMapper mapper;
    @Override
    public int insert(Branch branch) {
        return mapper.insert(branch);
    }

    @Override
    public PageInfo<Branch> listByParam(Page<Branch> page) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        return new PageInfo<>(mapper.listByParam(page.getData()));
    }

    @Override
    public Branch listById(Integer storesId, Integer bookId) {
        return mapper.listById(storesId,bookId);
    }

    @Override
    public int update(Branch branch) {
        return mapper.update(branch);
    }

    @Override
    public int updateMore(List<Branch> list) {
        int sum=0;
        for (Branch branch : list) {
            branch.setBookQty(branch.getBookQty()+ branch.getAddStock());
             mapper.updateMore(branch);
             sum++;
        }
        return sum;
    }
}
